/**
 * @file hash.h
 *
 * Hash table's header.
 *
 * @date 1998 - 2011
 * @author Richard Delorme
 * @version 4.1
 */

#ifndef EDAX_HASH_C
#define EDAX_HASH_C

#include <stdbool.h>
#include <stdio.h>

/** HashData : data stored in the hash table */
typedef struct HashData {
	unsigned char depth;      /*!< depth */
	unsigned char selectivity;/*!< selectivity */
	unsigned char cost;       /*!< search cost */
	unsigned char date;       /*!< dating technique */
	signed char lower;        /*!< lower bound of the position score */
	signed char upper;        /*!< upper bound of the position score */
	unsigned char move[2];    /*!< best moves */
} HashData;

/** Hash  : item stored in the hash table*/
typedef struct Hash {
	unsigned long long code;  /*!< hash code */
	HashData data;
} Hash;

/** HashTable: position storage */
typedef struct HashTable {
	Hash *hash;  				  /*!< hash table */
	void *memory;                 /*!< allocated memory */
	unsigned long long hash_mask; /*!< a bit mask */
	unsigned char date;
} HashTable;

/* declaration */
void hash_init(HashTable*, const unsigned int);
void hash_cleanup(HashTable*);
void hash_clear(HashTable*);
void hash_free(HashTable*);
void hash_store(HashTable*, const unsigned long long, const int, const int, const int, const int, const int, const int, const int);
void hash_force(HashTable*, const unsigned long long, const int, const int, const int, const int, const int, const int, const int);
bool hash_get(const HashTable*, const unsigned long long, HashData *);
void hash_copy(const HashTable*, HashTable*);
void hash_print(const HashData*, FILE*);
void hash_set(Hash*, const unsigned long long, const int, const int, const int, const int, const int, const int, const int);
bool hash_feed(Hash*, const unsigned long long, const int, const int, const int, const int, const int, const int);
void hash_exclude_move(HashTable*, const unsigned long long, const int);

extern const HashData HASH_DATA_INIT;

#endif

